package com.miyake.dsp.osa.lab.ui;

import java.awt.Component;
import java.awt.Point;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

public class MyPopupMenu {
	private static JPopupMenu wireMenu;
	private static JComponent wireMenuParent;

	
	public static JMenu createSubMenu(String name) {
		return new JMenu(name);
	}
	
	public static JMenuItem createMenuItem(String name, ActionListener actionListener) {
		JMenuItem menuItem = new JMenuItem(name);
		menuItem.addActionListener(actionListener);
		return menuItem;
	}
	
	public static void showWirePopup(JComponent c, Point location) {
		wireMenuParent = c;
		if (wireMenu == null) {
			wireMenu = new JPopupMenu();
			JMenuItem menuItem = new JMenuItem("Remove");
			menuItem.setVisible(true);
			wireMenu.add(menuItem);
		}
		wireMenu.setLocation(location);
		wireMenu.setVisible(true);
		wireMenuParent.add(wireMenu);
	}
	
	public static void hideWirePopup() {
		wireMenuParent.remove(wireMenu);
	}
}
